package com.hanhanxiaochong.zhongxiangchuanmei.view.home.act;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.ProjectEvaluationListBean;
import com.hanhanxiaochong.zhongxiangchuanmei.presenter.EvaluationListPresenter;
import com.hanhanxiaochong.zhongxiangchuanmei.view.base.BaseActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.home.adapter.EvaluationListAdapter;
import com.hanhanxiaochong.zhongxiangchuanmei.view.iview.IEvaluationListView;

import butterknife.BindView;

/**
 * 商品/项目评价
 */
public class EvaluationListActivity extends BaseActivity<EvaluationListPresenter> implements IEvaluationListView {


    @BindView(R.id.img_left)
    ImageView imgLeft;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.rv_evaluation_list)
    RecyclerView rvEvaluationList;
    //0项目，1产品
    private int type;
    private EvaluationListAdapter evaluationListAdapter;

    public static Intent createIntent(Context context, int type, String p_id) {
        Intent intent = new Intent(context, EvaluationListActivity.class);
        intent.putExtra("type", type);
        intent.putExtra("p_id", p_id);
        return intent;
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_evaluation_list);
    }

    @Override
    protected void initPresenter() {
        mPresenter = new EvaluationListPresenter(this);
    }

    @Override
    protected void init() {
        Intent intent = getIntent();
        type = intent.getIntExtra("type", 0);
        String p_id = intent.getStringExtra("p_id");
        setTopView();
        rvEvaluationList.setLayoutManager(new LinearLayoutManager(this));
        if (type == 0) {
            mPresenter.getProjectEvaluationList(p_id);
        } else {
            mPresenter.getProductEvaluationList(p_id);
        }
    }

    private void setTopView() {
        imgLeft.setImageResource(R.mipmap.icon_close_black);
        txtTitle.setText(type == 0 ? "项目评价" : "产品评价");
    }

    @Override
    public void setProjectEvaluationList(ProjectEvaluationListBean data) {
        evaluationListAdapter = new EvaluationListAdapter(this, data.getList());
        rvEvaluationList.setAdapter(evaluationListAdapter);
    }

    @Override
    public void setProductEvaluationList(ProjectEvaluationListBean data) {
        evaluationListAdapter = new EvaluationListAdapter(this, data.getList());
        rvEvaluationList.setAdapter(evaluationListAdapter);
    }
}
